/**
 *
 */
package de.cbf.cam.dsa.services.impl.rcp_provider;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.cbf.cam.dsa.rcp.model.entities.CultureDSA;
import de.cbf.cam.dsa.services.impl.rcp_provider.extension.interfaces.IRCPPersisterCulture;
import de.cbf.cam.dsa.services.interfaces.rcp_provider.IServiceDSAProviderCulture;
import de.cbf.cam.dsa.services.interfaces.rcp_provider.exceptions.EntityNotFoundException;
import de.cbf.util.db.interfaces.exceptions.EntityLoadException;
import de.cbf.util.db.interfaces.exceptions.EntitySaveException;
import de.cbf.util.uuidheader.entities.UUIDHeader;

/**
 * @author Alti
 *
 */
public class ProviderCulture implements IServiceDSAProviderCulture {
	private static final Log logger = LogFactory.getLog(ProviderCulture.class);
	protected IRCPPersisterCulture persister;

	public ProviderCulture() {
		super();
	}

	@Override
	public UUIDHeader getEntityByItsID(UUID id) throws EntityNotFoundException {
		CultureDSA culture;
		try {
			culture = persister.loadCulture(id);
		} catch (EntityLoadException e) {
			throw new EntityNotFoundException("CultureDSA NOT found,id: "+id,e);
		}
		return culture;
	}

	public List<CultureDSA> provideAllCultures(){
		List<CultureDSA> resultList = new ArrayList<CultureDSA>();
		try {
			resultList.addAll(persister.loadAllCultures());
		} catch (EntityLoadException e) {
			logger.error(e);
		}
		return resultList;
	}

	public void persistCulture(CultureDSA entity) {
		try {
			persister.saveCulture(entity);
		} catch (EntitySaveException e) {
			logger.error(e);
		}
	}

	@Override
	public String getName() {
		return "Culture provider via "+persister.getName();
	}

	public IRCPPersisterCulture getPersister() {
		return persister;
	}

	public void setPersister(IRCPPersisterCulture persister) {
		this.persister = persister;
	}
}
